home *** CD-ROM | disk | FTP | other *** search
- //---------------------------------------------------------------------------
- #include <vcl.h>
- #pragma hdrstop
-
- #include "SpeedTest.h"
- #include "ParseDemo.h"
- //---------------------------------------------------------------------------
- #pragma package(smart_init)
- #pragma resource "*.dfm"
- TFSpeedTest *FSpeedTest;
- //---------------------------------------------------------------------------
- __fastcall TFSpeedTest::TFSpeedTest(TComponent* Owner)
- : TForm(Owner)
- {
- }
- //---------------------------------------------------------------------------
- void __fastcall TFSpeedTest::BExitClick(TObject *Sender)
- {
- Close();
- }
- //---------------------------------------------------------------------------
-
-
- void __fastcall TFSpeedTest::FormShow(TObject *Sender)
- {
- ETimes->SetFocus();
- this->MFunction->Lines = FParser->MFunction->Lines;
- EResult->Text = "no result ...";
- LtheTime->Caption = "0";
- }
- //---------------------------------------------------------------------------
-
- void __fastcall TFSpeedTest::BStartClick(TObject *Sender)
- {
- int errPos;
- long double times;
- char tempstr[50];
-
- times = chartold(ETimes->Text.c_str(), &errPos);
-
- if ((errPos >= 0) || (times <= 0)) {
- MessageBox(Handle, "This is a numerical field and has to be positive.",
- "Error at 'How often?'",
- MB_ICONERROR);
- return;
- }
-
- int BaseIn;
- int BaseOut;
- int AngularUnit;
-
- //Get data (Base for Input/output and angular unit) from the main form
- FParser->GetBaseAndAngUnit(this, &BaseIn, &BaseOut, &AngularUnit);
-
- long double varValues[6];
- bool err = false;
-
- //Get data (values of the variables) from the main form
- err = FParser->GetVarValues(this, BaseIn, varValues);
- if (err)
- return;
-
- long double Result;
- long double AddedResult = 0;
- AnsiString funcStr = MFunction->Text.c_str();
- long ctime = GetCurrentTime();
-
- Screen->Cursor = crHourGlass;
- //Create an sbParser object and receive its HANDLE
- HANDLE hParser = CreateNewParser(funcStr.c_str(), BaseIn, 6, "xyzuvw");
- Screen->Cursor = crDefault;
- if (GetIsError(hParser)) {
- char errText[50];
-
- //An error has occurred (see documentation)
- MessageBox(Handle, ldtochar(errText, GetGlobalError(hParser)),
- "Errornumber in Function (see documentation)",
- MB_ICONERROR);
-
- //Delete of the sbParser-object
- DeleteParser(hParser);
- return;
- }
- SetAngularUnitTo(hParser, AngularUnit);
-
- //Creation time
- ctime = GetCurrentTime() - ctime;
- LtheTime0->Caption = ldtochar(tempstr, (long double)ctime/1000, 12);
-
- //Reset time
- ctime = GetCurrentTime();
- Screen->Cursor = crHourGlass;
- if (err) {
- EResult->Text = "Error";
- ctime = 0;
- }
- else
- for (long iCount = 1; iCount <= times; iCount++) {
- //Compute the result
- AddedResult = AddedResult + GetResultExt(hParser, varValues);
- if (GetIsError(hParser)) {
- char errText[50];
-
- //An error has occurred (see documentation)
- MessageBox(Handle, ldtochar(errText, GetGlobalError(hParser)),
- "Errornumber in Function (see documentation)",
- MB_ICONERROR);
- err = true;
- break;
- }
- }
- Screen->Cursor = crDefault;
-
- if (err) {
- EResult->Text = "Error";
- ctime = 0;
- }
- else {
- char tempstr[50];
-
- //Convert the long double to a string
- ConvertToBase(tempstr,AddedResult,15,BaseOut);
-
- EResult->Text = tempstr;
-
- ctime = GetCurrentTime() - ctime;
- }
-
- //Calculation time
- LtheTime->Caption = ldtochar(tempstr, (long double)ctime/1000, 12);
-
- //Delete of the sbParser-object
- DeleteParser(hParser);
- }
- //---------------------------------------------------------------------------
-
- void __fastcall TFSpeedTest::ETimesChange(TObject *Sender)
- {
- EResult->Text = "no result ...";
- }
- //---------------------------------------------------------------------------
-
-
-
-
-